package com.getinstaliker.instagram;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * The Class SessionStore.
 * @author HuanND
 */
public class SessionStore {
	
	/** The instance. */
	private static SessionStore INSTANCE 			= null;
	
	/** The Constant FILE_NAME. */
	private static final String FILE_NAME 			= "InstaSessionStore";
	
	/** The Constant ACCESS_TOKEN_KEY. */
	private static final String ACCESS_TOKEN_KEY 	= "Access_Token";
	
	/** The Constant API_USERNAME. */
	private static final String API_USERNAME 		= "Api_user_name";
	
	/** The Constant API_ID. */
	private static final String API_ID 				= "Api_Id";
	
	/** The Constant API_NAME. */
	private static final String API_NAME 			= "Api_name";
	
	/** The Constant API_ACCESS_TOKEN. */
	private static final String API_ACCESS_TOKEN 	= "Api_access_token";
	
	/** The Constant API_EMAIL. */
	private static final String API_EMAIL			= "Api_email";
	
	/** The Constant API_USER_IMAGE. */
	private static final String API_USER_IMAGE 		= "Api_user_image";
	    
	private static final String USER_COINS			= "user_coins";
	/**
	 * Instantiates a new session store.
	 */
	private SessionStore(){}
	
	/**
	 * Gets the single instance of SessionStore.
	 *
	 * @return single instance of SessionStore
	 */
	public static SessionStore getInstance(){
		if(INSTANCE==null){
			INSTANCE = new SessionStore();
		}
		return INSTANCE;
	}
	
	/**
	 * Gets the shared preferences.
	 *
	 * @return the shared preferences
	 */
	public SharedPreferences getSharedPreferences()
	{
		return InstaDefine.APP_CONTEXT.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
	}
	
	/**
	 * Save insta access toke.
	 *
	 * @param accessToken the access token
	 */
	public void saveInstaAccessToke(String accessToken) {
		Editor editor = getSharedPreferences().edit();
		editor.putString(API_ACCESS_TOKEN, accessToken);
		editor.commit();
	}
	
	/**
	 * Gets the insta access token.
	 *
	 * @return the insta access token
	 */
	public String getInstaAccessToken() {
		return getSharedPreferences().getString(API_ACCESS_TOKEN, null);
//		return "465257568.4b593f6.c01007db6a6446af9f5fae28273586c9";
	}
	
	public String getUserId(){
		return getSharedPreferences().getString(API_ID, null);
	}
	/**
	 * Save instagram session.
	 *
	 * @param token the token
	 * @param id the id
	 * @param username the username
	 * @param name the name
	 */
	public void saveInstagramSession(String token, String id, String username, String name)
	{
		Editor editor = getSharedPreferences().edit();
		editor.putString(API_ID, id);
		editor.putString(API_NAME, name);
		editor.putString(API_ACCESS_TOKEN, token);
		editor.putString(API_USERNAME, username);
		editor.commit();
	}
	
	public void saveUserCoins(String coins){
		Editor editor = getSharedPreferences().edit();
		editor.putString(USER_COINS, coins);
		editor.commit();
	}
	
	public String getUserCoins(){
		return getSharedPreferences().getString(USER_COINS, null);
	}
	
	//If you have other things saved in SharedPreference, clear things like this.
	
	/**
	 * Reset instagram.
	 */
	public void resetInstagram()
	{
		Editor editor = getSharedPreferences().edit();
		editor.remove(API_ID);
		editor.remove(API_NAME);
		editor.remove(API_ACCESS_TOKEN);
		editor.remove(API_USERNAME);
		editor.remove(API_EMAIL);
		editor.commit();
	}
	
	//If you have only Instagram value saved in SharedPreference, you can reset using this function as well.
	
	/**
	 * Reset instagream.
	 */
	public void resetInstagream(){
		Editor editor = getSharedPreferences().edit();
		editor.clear();
		editor.commit();
	}

}
